//translate.js

var util = require('../../../utils/util.js')
var app = getApp()
const domainUrl = app.globalData.domainUrl
// const domainUrl = "http://localhost:8771/"

Page({
  data: {
    duration: 2000,
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    loading: false,
    plain: false,
    userInfo: {},
    currentID: '0',
    menuItems: [
      {
        courseName: '水浒英雄',
        id: '0'
      },
      {
        courseName: '六大恶人',
        id: '1'
      },
      {
        courseName: '三国赤壁',
        id: '2'
      },
      {
        courseName: '三国武器',
        id: '3'
      },
      {
        courseName: '三国官渡',
        id: '4'
      }
    ],
  },
  onLoad: function (params) {
    util.login(this.route);
    var that = this;
    var openid = wx.getStorageSync('my_openid');
    wx.request({
      url: domainUrl + 'queryCardListByType?type=0&openId=' + openid,
      success: function (res) {
        console.log(res.data);
        that.setData({
          dataList: res.data
        })
      }
    });
    wx.request({
      url: domainUrl + 'transParamItem?type=4',
      success: function (res) {
        console.log(res.data);
        that.setData({
          menuItems: res.data.data
        })
      }
    })
  },
  tapMenuItem: function (e) {
    var that = this;
    
    var openid = wx.getStorageSync('my_openid');
    console.log(e.currentTarget.id);
    var id = e.currentTarget.id;

    var url = domainUrl + 'queryCardListByType?type='+id+'&openId='+openid;
    
    wx.request({
      url: url,
      success: function (res) {
        console.log(res.data);
        that.setData({
          dataList: res.data,
          currentID: e.currentTarget.id
        })
      }
    })
  },
  switchNav(event){
    var cur = event.currentTarget.dataset.current; 
    //每个tab选项宽度占1/5
    var singleNavWidth = this.data.windowWidth / 5;
    //tab选项居中                            
    this.setData({
      navScrollLeft: (cur - 2) * singleNavWidth
    })      
    if (this.data.currentTab == cur) {
      return false;
    } else {
      this.setData({
        currentTab: cur
      })
    }
  },
  onReady: function () {
    wx.setNavigationBarTitle({ title: '我的卡包', success: function (res) { } });
    this.innerAudioContext = wx.createInnerAudioContext();
  },
  onShow: function () {
    console.log("显示图片")
    var that = this;
    that.setData({
      currentID: '0'
    })
    var openid = wx.getStorageSync('my_openid');
    this.onLoad();
  },

  translateText: function (e) { this.setData({ translateValue: e.detail.value }) },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '水浒卡',
      path: '/pages/card/card',
      success: function (res) { },
      fail: function (res) { }
    }
  }
})